<?php


namespace app\admin\model;


use think\Model;

class OrderInfoModel extends Model
{
    public function company()
    {
        return $this->hasOne('CompanyModel', 'id', 'company_id')->bind([
            'company_name' => 'name'
        ]);
    }

    public function userInfo()
    {
        return $this->hasOne('WechatUserModel', 'id', 'user_id')->bind([
            'user_name' => 'nickname'
        ]);
    }

    public function getOrderStatusAttr($value)
    {
        $status = [0 => '确认订单', 1 => '取消订单', 2 => '退款订单'];
        return $status[$value];
    }

    public function getPayStatusAttr($value)
    {
        $status = [0 => '未支付', 1 => '待支付', 2 => '已支付', 3 => '已退款'];
        return $status[$value];
    }

    public function getShippingStatusAttr($value)
    {
        $status = [0 => '未发货', 1 => '已发货', 2 => '已退货', 3 => '已收货'];
        return $status[$value];
    }

    public function orderGoodsList()
    {
        return $this->hasMany('OrderGoodsModel', 'order_id');
    }

    public function couponInfo()
    {
        return $this->hasOne('CouponModel', 'card_id', 'card_id');
    }

    public function refundInfo()
    {
        return $this->hasOne('ApplyRefundModel', 'order_sn', 'order_sn');
    }

    public function adminLog()
    {
        return $this->hasMany('AdminLogModel', 'order_sn', 'order_sn');
    }
}
